﻿using QC;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;


namespace ReportsClassLibrary
{
    public class Report:IReports
    {
        // public string connectionString = @"Data Source=t-sql;Initial Catalog=Measurement;Integrated Security=True"; // CPCC DB CONNECTION
        public string connectionString = @"Data Source=MYLAPTOP;Initial Catalog=Measurement;Integrated Security=True";
        public string MaterialName { get; set; }
        public string DateTaken { get; set; }
        public string Pass_Fail { get; set; }
        public string OnTime { get; set; }
        public string Delayed { get; set; }

        public List<Report> GetReportData(DateTime startDate, DateTime endDate, string type)
        {
            DataTable dt = new DataTable();
            using (var con = new SqlConnection(connectionString))
            using (var cmd = new SqlCommand("GetMeasurementDataForReports", con))
            using (var da = new SqlDataAdapter(cmd))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@startDate ", SqlDbType.DateTime).Value = startDate;
                cmd.Parameters.Add("@endDate ", SqlDbType.DateTime).Value = endDate;
                cmd.Parameters.Add("@type", SqlDbType.VarChar, 10).Value = type;
                da.Fill(dt);
            }

            List<Report> allReportData = new List<Report>();
            foreach (DataRow dr in dt.Rows)
            {
                allReportData.Add(new Report
                {
                    MaterialName = dr["MaterialName"].ToString(),
                    DateTaken = dr["DateTaken"].ToString(),
                    Pass_Fail = dr["Pass_Fail"].ToString(),
                    OnTime = dr["OnTime"].ToString(),
                    Delayed = dr["Delayed"].ToString()
                });
            }
            return allReportData;
        }
    }
}
